﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SAIN.MVC.Controllers
{
    public class UsuariosController : Controller
    {
        //
        // GET: /Usuarios/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LoginControl()
        {
            return View();
        }
        public ActionResult Login(string user, string password)
        {
            try
            {
                if (new Membership().Login(user,password))
                {
                    return View("Index");
                }
                return RedirectToAction("Login", "Home");
            }
            catch (Exception ex)
            {
                throw new Exception("ERROR - ", ex);
            }
        }
        [HttpPost]
        public ActionResult Login(FormCollection form)
        {
            try
            {
                bool flag = new Membership().Login(form["user"], form["password"]);
                var result = new {Success = flag.ToString(), Message="Login"};
                return Json(result,JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                throw new Exception("ERROR - ", ex);
            }
            return View();
        }
    }
}
